<template>
    <div>
        <Form :label-width="100" inline>
            <Form-item label="属地区划:">
                <area-linkage :areaCode.sync="queryParam.ssdg0009" :countyDisable=countyState :streetDisable=streetState
                              :communityDisable=communityState></area-linkage>
            </Form-item>
            <Form-item label="人员姓名:">
                <Input v-model="queryParam.ssdg0001" placeholder="请输入人员姓名" style="width:160px"/>
            </Form-item>

            <Form-item label="身份证号码:">
                <Input v-model="queryParam.ssdg0002" placeholder="请输入身份证号码" style="width:200px"/>
            </Form-item>
            <Form-item label="人员状态:">
                <c-dict-select v-model="queryParam.ssdg0031" dictCode="personstateforzq" style="width:100px"/>
            </Form-item>
        </Form>
        <Row class="button_row">
                <span style="float: left;">
                  <Button type="primary" @click="handleAdd()">录入</Button>
                  <Button type="primary" class="button_item_left" @click="handleEdit()">编辑</Button>
                  <Button type="primary" class="button_item_left" @click="handleView()">查看</Button>
                </span>
            <span style="float: right;">
                 <Button type="primary" @click="searchQuery">查询</Button>
                 <Button type="primary" class="button_item_left" @click="searchReset">重置</Button>
                </span>
        </Row>
        <div>
            <Modal v-model="visible" :title="title" width="1000" style="position:relative;">
                <Form ref="formData" :model="formData" :label-width="150" :rules="rules">
                    <table>
                        <tr>
                            <td colspan="2">
                                <FormItem label="行政区划" prop="ssdg0009">
                                    <area-linkage :areaCode.sync="formData.ssdg0009" :countyDisable=countyState
                                                  :streetDisable=streetState
                                                  :communityDisable=communityState></area-linkage>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="姓名" prop="ssdg0001">
                                    <Input v-model="formData.ssdg0001" placeholder="" style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="身份证号" prop="ssdg0002">
                                    <Input v-model="formData.ssdg0002" placeholder="" style="width: 200px"
                                           @on-blur="checkIdcard()"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="性别">
                                    <c-dict-select v-model="formData.ssdg0003" dictCode="sex" :width="200"
                                                   :clearable="true"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="出生日期">
                                    <DatePicker type="date" v-model="formData.ssdg0005" placeholder="请选择出生日期"
                                                style="width: 200px"   :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="联系方式">
                                    <Input v-model="formData.ssdg0004" placeholder="" number style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="社会养老保险">
                                    <c-dict-select v-model="formData.ssdg0006" dictCode="socialpension" :width="200"
                                                   :clearable="true"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="下乡时间" prop="ssdg0007">
                                    <DatePicker type="date" v-model="formData.ssdg0007" placeholder="请选择下乡时间"
                                                style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="回城时间" prop="ssdg0008">
                                    <DatePicker type="date" v-model="formData.ssdg0008" placeholder="请选择回城时间"
                                                style="width: 200px"   :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="户口所在地详细地址">
                                    <Input v-model="formData.ssdg0011" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="现居住地详细地址" prop="ssdg0013">
                                    <Input v-model="formData.ssdg0013" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="下乡地点">
                                    <Input v-model="formData.ssdg0014" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="银行账号">
                                    <Input v-model="formData.ssdg0015" placeholder="" number style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="开户银行">
                                    <Input v-model="formData.ssdg0016" placeholder="" style="width: 200px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="开户名称">
                                    <Input v-model="formData.ssdg0017" placeholder="" style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="最低生活保障标准" prop="ssdg0018">
                                    <Input v-model="formData.ssdg0018" number placeholder="" style="width: 200px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="公安部门意见">
                                    <Input v-model="formData.ssdg0019" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="公安部门审核人">
                                    <Input v-model="formData.ssdg0020" placeholder="" style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="公安部门审核日期">
                                    <DatePicker type="date" v-model="formData.ssdg0021" placeholder="请选择公安部门审核日期"
                                                style="width: 200px"   :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="养老中心意见">
                                    <Input v-model="formData.ssdg0022" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="养老中心审核人">
                                    <Input v-model="formData.ssdg0023" placeholder="" style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="养老中心审核日期">
                                    <DatePicker type="date" v-model="formData.ssdg0024" placeholder="请选择养老中心审核日期"
                                                style="width: 200px"   :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="劳动部门意见">
                                    <Input v-model="formData.ssdg0025" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="劳动部门审核人">
                                    <Input v-model="formData.ssdg0026" placeholder="" style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="劳动部门审核日期">
                                    <DatePicker type="date" v-model="formData.ssdg0027" placeholder="请选择劳动部门审核日期"
                                                style="width: 200px"  :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="民政部门意见">
                                    <Input v-model="formData.ssdg0028" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="民政部门审核人">
                                    <Input v-model="formData.ssdg0029" placeholder="" style="width: 200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="民政部门审核日期">
                                    <DatePicker type="date" v-model="formData.ssdg0030" placeholder="请选择民政部门审核日期"
                                                style="width: 200px"  :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="人员状态" prop="ssdg0031">
                                    <c-dict-select v-model="formData.ssdg0031" dictCode="personstateforzq"
                                                   style="width:200px"/>
                                </FormItem>
                            </td>
                            <td>
                                <FormItem label="开始享受时间" prop="ssdg0034">
                                    <DatePicker type="date" v-model="formData.ssdg0034" placeholder="请选择开始享受时间"
                                                style="width: 200px"  :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <FormItem label="注销时间">
                                    <DatePicker type="date" v-model="formData.ssdg0033" placeholder="请选择注销时间"
                                                style="width: 200px"  :editable="false"></DatePicker>
                                </FormItem>
                            </td>
                            <td>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="注销原因">
                                    <Input v-model="formData.ssdg0032" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <FormItem label="备注">
                                    <Input v-model="formData.remarks" placeholder="" style="width: 566px"/>
                                </FormItem>
                            </td>
                        </tr>
                    </table>
                </Form>
                <div slot="footer">
                    <Button @click="visible = false">关闭</Button>
                    <Button type="primary" @click="handleSubmit('formData')" v-if="showSubmit">确定</Button>
                </div>
            </Modal>
        </div>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       @cell-click="selectChange"
                       :data="tableData">
                <vxe-table-column type="radio" width="60" align="center" fixed="left"/>
                <vxe-table-column field="ssdg0001" title="姓名" align="center" width="120" fixed="left"/>
                <vxe-table-column field="ssdg0002" title="身份证号码" align="center" width="200" fixed="left"/>
                <vxe-table-column field="azaa0002" title="属地区划" align="center" width="200" fixed="left"/>
                <vxe-table-column field="ssdg0018" title="最低生活保障标准" align="center" width="150"/>
                <vxe-table-column field="ssdg0031_name" title="人员状态" align="center" width="120"/>
                <vxe-table-column field="ssdg0034" title="开始享受时间" align="center" width="150" :formatter="renderTime"/>
                <vxe-table-column field="ssdg0033" title="注销时间" align="center" width="150" :formatter="renderTime"/>
                <vxe-table-column field="ssdg0007" title="下乡时间" align="center" width="150" :formatter="renderTime"/>
                <vxe-table-column field="ssdg0008" title="回城时间" align="center" width="150" :formatter="renderTime"/>
                <vxe-table-column field="ssdg0003_name" title="性别" dictCode="sex" align="center" width="100"/>
                <vxe-table-column field="ssdg0004" title="联系方式" align="center" width="150"/>
                <vxe-table-column field="ssdg0005" title="出生日期" align="center" width="150" :formatter="renderTime"/>
                <vxe-table-column field="ssdg0006_name" title="社会养老保险" align="center" width="120"/>
                <vxe-table-column field="ssdg0011" title="户口所在地详细地址" align="center" width="300"/>
                <vxe-table-column field="ssdg0013" title="现居住地详细地址" align="center" width="300"/>
                <vxe-table-column field="ssdg0014" title="下乡地点" align="center" width="300"/>
                <vxe-table-column field="ssdg0015" title="银行账号" align="center" width="200"/>
                <vxe-table-column field="ssdg0016" title="开户银行" align="center" width="120"/>
                <vxe-table-column field="ssdg0017" title="开户名称" align="center" width="120"/>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>

    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import DateFormat from '@/plugins/format.js'
    import {IdentityCodeValid} from '@/plugins/idcardValid.js'


    export default {
        mixins: [CommonMixin],
        components: {},
        data() {
            return {
                countyState: false,
                streetState: false,
                communityState: false,
                fieldsToValidate: ['ssdg0009', 'ssdg0001', 'ssdg0002', 'ssdg0007', 'ssdg0008', 'ssdg0013', 'ssdg0018', 'ssdg0031', 'ssdg0034'],
                rules: {
                    ssdg0009: [
                        {required: true, message: '请选择属地区划', trigger: 'blur'}
                    ],
                    ssdg0001: [
                        {required: true, message: '请输入姓名', trigger: 'blur'}
                    ],
                    ssdg0002: [
                        {required: true, message: '请输入身份证号', trigger: 'blur'}
                    ],
                    ssdg0007: [
                        {required: true, message: '请选择下乡时间', trigger: 'blur', type: 'date'}
                    ],
                    ssdg0008: [
                        {required: true, message: '请选择回城时间', trigger: 'blur', type: 'date'},
                    ],
                    ssdg0013: [
                        {required: true, message: '请填写现居住地详细地址', trigger: 'blur'},
                    ],
                    ssdg0018: [
                        {required: true, message: '请填写最低生活保障标准', trigger: 'blur', type: 'number'},
                    ],
                    ssdg0031: [
                        {required: true, message: '请选择人员状态', trigger: 'change'},
                    ],
                    ssdg0034: [
                        {required: true, message: '请选择开始享受时间', trigger: 'blur', type: 'date'},
                    ]
                },
                tableData: [],
                Loading: false,
                url: {
                    list: "/api/ac/subsistence/ss13007Service/getPageList",
                    add: "/api/ac/subsistence/ss13007Service/insertData",
                    edit: "/api/ac/subsistence/ss13007Service/updateData",
                    delete: "/api/ac/subsistence/ss13007Service/deleteData",
                },
                formData: {},
                queryParam: {},
                visible: false,
                showSubmit: true,
                dataCount: 0,
                pageSize: 10,
                modal: false,
                title: ""
            }
        },
        methods: {
            selectChange({row}) {
                this.$refs.xTree.setRadioRow(row);
                this.selectedData = row;
            },
            handleAdd() {
                let that = this;
                that.title = "录入"
                let record = {};
                that.visible = true
                that.showSubmit = true
                that.formData = Object.assign({}, record)
            },
            handleEdit(index) {
                let that = this;
                if (that.selectedData == '' || that.selectedData == undefined) {
                    that.$Message.error('请选中一条数据!')
                    return false;
                }
                that.title = "编辑"
                let record = that.selectedData;
                if (record.id) {
                    that.visible = true
                    that.showSubmit = true
                    that.formData = Object.assign({}, record)
                    if (that.formData.ssdg0005) {
                        that.formData.ssdg0005 = new Date(record.ssdg0005);
                    }
                    if (that.formData.ssdg0007) {
                        that.formData.ssdg0007 = new Date(record.ssdg0007);
                    }
                    if (that.formData.ssdg0008) {
                        that.formData.ssdg0008 = new Date(record.ssdg0008);
                    }
                    if (that.formData.ssdg0021) {
                        that.formData.ssdg0021 = new Date(record.ssdg0021);
                    }
                    if (that.formData.ssdg0024) {
                        that.formData.ssdg0024 = new Date(record.ssdg0024);
                    }
                    if (that.formData.ssdg0027) {
                        that.formData.ssdg0027 = new Date(record.ssdg0027);
                    }
                    if (that.formData.ssdg0030) {
                        that.formData.ssdg0030 = new Date(record.ssdg0030);
                    }
                    if (that.formData.ssdg0033) {
                        that.formData.ssdg0033 = new Date(record.ssdg0033);
                    }
                    if (that.formData.ssdg0034) {
                        that.formData.ssdg0034 = new Date(record.ssdg0034);
                    }
                } else {
                    that.visible = false
                }
            },
            handleView(index) {
                let that = this;
                if (that.selectedData == '' || that.selectedData == undefined) {
                    that.$Message.error('请选中一条数据!')
                    return false;
                }
                that.title = "查看"
                let record = that.selectedData;
                if (record.id) {
                    that.visible = true
                    that.showSubmit = false
                    that.formData = Object.assign({}, record)
                    that.formData.ssdg0005 = new Date(record.ssdg0005);
                    that.formData.ssdg0007 = new Date(record.ssdg0007);
                    that.formData.ssdg0008 = new Date(record.ssdg0008);
                    that.formData.ssdg0021 = new Date(record.ssdg0021);
                    that.formData.ssdg0024 = new Date(record.ssdg0024);
                    that.formData.ssdg0027 = new Date(record.ssdg0027);
                    that.formData.ssdg0030 = new Date(record.ssdg0030);
                    that.formData.ssdg0033 = new Date(record.ssdg0033);
                    that.formData.ssdg0034 = new Date(record.ssdg0034);
                } else {
                    that.visible = false
                }
            },
            handleSubmit(name) {
                let that = this;
                let validate = true;
                let err_msg = [];
                that.Loading = true;
                for (let item of that.fieldsToValidate) {
                    that.$refs[name].validateField(item, (error) => {
                        if (error) {
                            validate = false;
                            err_msg.push(error);
                        }
                    })
                }
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let that = this;
                        let url = null;
                        if (that.formData.id == null) {
                            url = that.url.add
                        } else {
                            url = that.url.edit
                        }
                        if (that.formData.ssdg0005 != undefined && that.formData.ssdg0005 != '') {
                            that.formData.ssdg0005 = DateFormat(that.formData.ssdg0005, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0005 = null}
                        if (that.formData.ssdg0007 != undefined && that.formData.ssdg0007 != '') {
                            that.formData.ssdg0007 = DateFormat(that.formData.ssdg0007, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0007 = null}
                        if (that.formData.ssdg0008 != undefined && that.formData.ssdg0008 != '') {
                            that.formData.ssdg0008 = DateFormat(that.formData.ssdg0008, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0008 = null}
                        if (that.formData.ssdg0021 != undefined && that.formData.ssdg0021 != '') {
                            that.formData.ssdg0021 = DateFormat(that.formData.ssdg0021, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0021 = null}
                        if (that.formData.ssdg0024 != undefined && that.formData.ssdg0024 != '') {
                            that.formData.ssdg0024 = DateFormat(that.formData.ssdg0024, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0024 = null}
                        if (that.formData.ssdg0027 != undefined && that.formData.ssdg0027 != '') {
                            that.formData.ssdg0027 = DateFormat(that.formData.ssdg0027, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0027 = null}
                        if (that.formData.ssdg0030 != undefined && that.formData.ssdg0030 != '') {
                            that.formData.ssdg0030 = DateFormat(that.formData.ssdg0030, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0030 = null}
                        if (that.formData.ssdg0033 != undefined && that.formData.ssdg0033 != '') {
                            that.formData.ssdg0033 = DateFormat(that.formData.ssdg0033, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0033 = null}
                        if (that.formData.ssdg0034 != undefined && that.formData.ssdg0034 != '') {
                            that.formData.ssdg0034 = DateFormat(that.formData.ssdg0034, 'YYYY-MM-DD')
                        }else{that.formData.ssdg0034 = null}
                        postAction(url, that.formData).then((res) => {
                            if (res.data.data.code == 1) {
                                that.visible = false
                                this.$Message.success("提交成功！")
                                this.loadData();
                                that.selectedData = null
                            } else {
                                this.$Message.error(res.data.data.msg);
                            }
                        }).finally(() => {

                        })
                    } else {
                        this.$Notice.error({title: '必填信息未填写完成!', desc: '必填信息未填写完成!'})
                    }
                    that.Loading = false;

                });
            },
            handleDelete() {
                let that = this;
                if (that.selectedData == '' || that.selectedData == undefined) {
                    that.$Message.error('请选中一条数据!')
                    return false;
                } else {
                    this.$Modal.confirm({
                        title: '确定删除吗？',
                        onOk: () => {
                            postAction(that.url.delete, that.selectedData).then((res) => {
                                if (res.data.errcode == 0) {
                                    that.$Message.success("删除成功！");
                                    this.loadData();
                                } else {
                                    that.$Message.error(res.data.errmsg);
                                }
                            });
                        }
                    })
                }
            },
            checkIdcard() {  //验证身份证是否合法并判断证件上传类型
                let that = this
                let ssdg0002 = that.formData.ssdg0002
                if (ssdg0002 != '' && typeof (ssdg0002) != 'undefined') {
                    ssdg0002 = ssdg0002.toUpperCase()
                    that.formData.ssdg0002 = ssdg0002
                    if (!IdentityCodeValid(ssdg0002)) {
                        that.$Message.error('身份证号码格式不合法')
                        that.formData.ssdg0002 = null
                        return
                    }
                    let dataParam = {};
                    dataParam.ssdg0002 = ssdg0002;
                    if (that.formData.id == undefined) {
                        dataParam.id = "null";
                    } else {
                        dataParam.id = that.formData.id;
                    }
                    postAction('/api/ac/subsistence/ss13007Service/checkIdcard', dataParam).then((res) => {
                        if (res.data.errcode == 0) {
                            // that.$Message.success("删除成功！");
                            if (res.data.data.msg == 'false') {
                                that.$Message.error("该身份证号码已录入过系统");
                                that.formData.ssdg0002 = null
                            }
                        } else {
                            that.$Message.error("系统出现问题, 请联系管理员");
                        }
                    });
                }
            },
        },
        created() {
            this.loadData();
        },
    }
</script>
<style scoped>
    /deep/ .ivu-form-item-error-tip {
        display: none;
    }

    .itemStyle {
        width: 180px
    }

    .head-img1 {
        height: 200px;
        width: 250px;
        margin-top: 15px;
    }

    .head-img {
        height: 200px;
        width: 250px;
    }

    .imgBackColor {
        background-color: WhiteSmoke;
        height: 250px;
    }

    .positiveTDiv {
        height: 240px;
        width: 75px;
        line-height: 240px;
        background-color: #7CCD7C;
        margin-bottom: 10px;
        color: white;
        font-size: 14px;
        font-weight: 700;
    }

    /deep/ .ivu-table .demo-table-info-cell-age {
        background-color: #ff6600;
        color: #fff;
    }

    /deep/ .ivu-table .demo-table-info-cell-ssfc0015_name {
        background-color: #f33e3e;
        color: #fff;
    }
</style>
